<?php

namespace App\Http\Controllers\Api\v1;

use App\common;
use App\Http\Controllers\Controller;
use App\Logic\AdminLogic;
use App\server\SMS\CodeServer;
use Illuminate\Http\Request;

/**
 * Undocumented class
 *  后台用户
 * @name zf
 */
class AdminController extends Controller
{
    /**
     * 后台用户列表
     */
    public function adminList(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $paginate=$request->get('paginate');
            $adminList=AdminLogic::AdminList($paginate);
            return common::success(20000,$adminList,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
    /**
     * 后台用户搜索
     */
    public function adminSearch(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $name=$request->get('name');
            $phone=$request->get('phone');
            $paginate=$request->get('paginate');
            $adminList=AdminLogic::AdminSearch($name,$phone,$paginate);
            return common::success(20000,$adminList,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
     /**
     * Undocumented function
     *  用户详情
     * @return void
     */
    public function adminDetail(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $user=$request->get('user');
            $id=$request->get('id');
            $adminDetail=AdminLogic::adminDetail($user,$id);
            return common::success(20000,$adminDetail,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
     }
     /**
     * Undocumented function
     *  添加用户信息
     * @return void
     */
    public function adminSave(Request $request){
        try{
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $updata=$request->post();
            $save=AdminLogic::adminSave($updata,$request);
            return common::success(20000,$save,'添加成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
     }
      /**
     * Undocumented function
     *  编辑用户信息
     * @return void
     */
    public function adminUpdate(Request $request){
        try{
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $updata=$request->post();
            $save=AdminLogic::adminUpdate($updata,$request);
            return common::success(20000,$save,'修改成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
     }
    /**
     * Undocumented function
     *  发送验证码
     * @return void
     */
    public function sendCode(Request $request){
        try{
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $tel=$request->post('tel');
            $type=$request->post('type');
            $code=AdminLogic::sendCode($tel,$type,$request);
            return common::success(20000,$code,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
     /**
     * Undocumented function
     *  验证验证码
     * @return void
     */
    public function verifyCode(Request $request)
    {
        try {
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $key = $request->post();
            $status = AdminLogic::verifyCode($key,$request);
            if ($status == true) {
                return common::success(20000, '', '验证成功');
            }
        } catch (\Exception  $e) {
            return common::fail(2001, '', $e->getMessage());
        }
    }
    /**
     * Undocumented function
     *  用户登录注册
     * @return void
     */
    public function adminLogin(Request $request){
        try{
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $key=$request->post();
            $user=AdminLogic::adminLogin($key,$request);
                return common::success(20000,$user,'登录成功');
        }catch(\Exception  $e){

            return common::fail(2001,'',$e->getMessage());
        }
    }
    /**
     * Undocumented function
     *  用户绑定手机号
     * @return void
     */
    public function adminPhone(Request $request){
        try{
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $key=$request->post();
            $status=AdminLogic::adminPhone($key,$request);
                return common::success(20000,$status,'绑定成功');
        }catch(\Exception  $e){

            return common::fail(2001,'',$e->getMessage());
        }
    }
     /**
     * 用户会员权限
     */
    public function adminMember(Request $request){

        try{
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $key=$request->post();
            $res=AdminLogic::adminMember($key);
                return common::success(20000,$res,'查询成功');
        }catch(\Exception  $e){

            return common::fail(2001,'',$e->getMessage());
        }
    }
     /**
     * 用户删除
     */
    public function adminDel(Request $request){

        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $id=$request->get('id');
            $adminDel=AdminLogic::adminDel($id);
            return common::success(20000,$adminDel,'删除成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }

}
